package org.example.new_hbps_backend_reconstruction.controller.patient;

/**
 * @author 丁利军
 * @date 2025年10月16日 15:17
 * @description 批量向心永腕表推送消息
 */

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.example.new_hbps_backend_reconstruction.common.results.R;
import org.example.new_hbps_backend_reconstruction.dto.BatchNotifyByUidsReq;
import org.example.new_hbps_backend_reconstruction.dto.BatchNotifyReq;
import org.example.new_hbps_backend_reconstruction.service.WatchNotifyService;
import org.springframework.http.HttpHeaders;
import org.springframework.web.bind.annotation.*;

@RestController
@RequiredArgsConstructor
@RequestMapping("/patient/deviceNotify")
@Tag(name = "设备-批量消息推送", description = "给心永手表批量推送消息")
@SecurityRequirement(name = HttpHeaders.AUTHORIZATION)
@Slf4j
public class WatchBatchNotifyController {

    private final WatchNotifyService watchNotifyService;

    @Operation(summary = "按 extUserIds 批量推送消息",
            description = "extUserIds 为心永三方用户 id，多个用英文逗号分隔；其余字段参照文档。")
    @ApiResponses({
            @ApiResponse(responseCode = "200", description = "推送成功"),
            @ApiResponse(responseCode = "400", description = "参数错误", content = @Content(schema = @Schema(implementation = R.class))),
            @ApiResponse(responseCode = "500", description = "服务器内部错误")
    })
    @PostMapping("/batchNotify")
    public R<?> batchNotify(@RequestBody BatchNotifyReq req) {
        log.info("batchNotify -> {}", req);
        return watchNotifyService.batchNotify(req);
    }

    @Operation(summary = "按患者 uid 批量推送消息",
            description = "后端根据患者 uid 映射为 extUserIds（pddId），再调用批量推送。")
    @ApiResponses({
            @ApiResponse(responseCode = "200", description = "推送成功"),
            @ApiResponse(responseCode = "400", description = "参数错误", content = @Content(schema = @Schema(implementation = R.class))),
            @ApiResponse(responseCode = "500", description = "服务器内部错误")
    })
    @PostMapping("/batchNotifyByUids")
    public R<?> batchNotifyByUids(@RequestBody BatchNotifyByUidsReq req) {
        log.info("batchNotifyByUids -> {}", req);
        return watchNotifyService.batchNotifyByUids(req);
    }
}

